//index.js
import loginFn from '../../utils/login'
import urls from '../../utils/urls'
//获取应用实例
const app = getApp()

Page({
    data: {
        showauth: false, //显示授权登陆
        noauth: true, //隐藏点击框
        imgUrls: [],
        bannerlist: [], //banner列表
        indicatorDots: true, //是否显示面板指示点
        autoplay: true, //自动播放
        interval: 5000, //自动切换时间间隔
        duration: 1000, //滑动动画时长
        indicatorColor: "#B5B5B5", //轮播点
        navList: [
            {
                'icon': '../../img/nav@3x.png'
            },
            {
                'icon': '../../img/interests@3x.png'
            }, {
                'icon': '../../img/language@3x.png'
            }, {
                'icon': '../../img/early@3x.png'
            },
            {
                'icon': '../../img/professional@3x.png'
            }
        ],
        listData: []
    },
    searchtxt: '', //关键词
    //生命周期
    onLoad: function(options) {
        console.log('options:',options);
        var that = this;

        //banner
        this.getbanner()
        //定位
        app.getLocation(() => {
            that.getcourse();
        })
        
    },
    onShow: function() {
    },
    onPullDownRefresh: function() {
        //banner
        this.getbanner()
        //定位
        app.getLocation(() => {
            this.getcourse();
            wx.stopPullDownRefresh();
        })
    },

    //轮播广告
    getbanner: function() { //banner
        var that = this;
        app.request({
            url: 'ad/index',
            sCallback:(res) => {
                if(res.code == 1) {
                    that.setData({
                        imgUrls: res.data.banner,
                        bannerlist: res.data
                    })
                }
            }
        })
    },
    getcourse: function() { //课程列表
        var that = this;
        app.request({
            url: 'course/hot',
            sCallback:(res) => {
                if(res.code == 1) {
                    that.setData({
                        listData: res.data
                    })
                }
            }
        })
    },
    course_serchFn: function(e) { //搜索输入
        this.searchtxt = e.detail.value
    },
    seachekeyword: function(e) { //搜索
        if (this.searchtxt.trim() !== '') {
            wx.navigateTo({
                url: '/pages/searchclass/index?keyword=' + this.searchtxt,
            })
        }

    },

    onShareAppMessage: function() {
	   return {
        title: '来这里找学校、找课程、找老师，靠谱！'
       }	
	},
})